﻿using System;
using System.Collections.Generic;
using System.Text;
using com.lover.astd.common.model;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Ipc;
using System.Threading;

namespace com.lover.astd.selector
{
    public class GameMgr
    {
        private static Selector _selector;
        private static Dictionary<string, Game> _games = new Dictionary<string, Game>();
        public static void setSelector(Selector selector){ _selector = selector; }
        public static void addGame(AccountData acc)
        {
        }
        private static void handleGameEvent(string gameId, GameEvent evt)
        {
            Game game = getGame(gameId);
            if (game == null) return;

            game.handleEvent(evt);
            _selector.refreshStatus();
        }
        public static Game getGame(string gameId)
        {
            if (!_games.ContainsKey(gameId)) return null;
            Game game = _games[gameId];
            if (game == null)
            {
                _games.Remove(gameId);
                return null;
            }
            return game;
        }
        public static void showGame(string gameId)
        {
            Game game = getGame(gameId);
            if (game == null) return;
        }
        public static void removeGame(string gameId)
        {
            Game game = getGame(gameId);
            if (game == null) return;
            game.dispose();
            _games.Remove(gameId);
        }
        public static void removeAllGames()
        {
            foreach (Game game in _games.Values)
            {
                if (game == null) continue;
                game.dispose();
            }
            _games.Clear();
        }
        public static void startLogin()
        {
        }
    }
}
